home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / cppcom.zip / DIALER2.CPP < prev    next >
C/C++ Source or Header  |  1991-05-25  |  3KB  |  95 lines

  1. /***************************************************************************
  2. These C++ classes are copyright 1990, by William Herrera.
  3. All those who put this code or its derivatives in a commercial product MUST
  4. mention this copyright in their documentation for users of the products in
  5. which this code or its derivative classes are used.  Otherwise, this code
  6. may be freely distributed and freely used for any purpose.
  7.  
  8. Enhancements: 1991 by David Orme
  9.     *  General cleanup.
  10.             - I/O now takes advantage of C++ overloading.
  11.             - Serial port I/O functionality now only in Serial class.
  12.             - Modem functionality now only in Modem class.
  13.     *  Possible to easily implement file Xfr prots now.
  14.     *  CCITT CRC-16 class added                            -- 2-20-1991
  15.     *  BIOS Timer class added                                -- 2-22-1991
  16.     *  Optional timeout on all input routines added    -- 2-25-1991
  17.  
  18. ***************************************************************************/
  19.  
  20. #include        <stdio.h>
  21. #include        <conio.h>
  22. #include        <string.h>
  23. #include        <stdlib.h>
  24. #include        <dos.h>
  25.  
  26. #include        "modem.hpp"
  27.  
  28. static const int defaultspeed = 2400;
  29. // change to suit if your modem cannot do 2400 bps!
  30.  
  31. int xgetch(void)
  32. {
  33.    // ibm pc keyboard extended getch().
  34.    int ch;
  35.    return ( (ch = getch()) != 0 ) ? ch : getch() + 256;
  36. }
  37.  
  38.  
  39. int main()
  40. {
  41.     int port = 4;        // change this to suit your config
  42.     int speed=defaultspeed;
  43.  
  44.     modem m(port, speed, NOPAR, 1, 8, false);
  45.  
  46.     m.RaiseDTR();  // FAILS: raise DTR
  47.  
  48.     printf("Current baud rate is %d\n", m.GetSpeed());
  49.     printf("Alt-B set baud rate, Alt-S shell, Alt-X exit\n");
  50.     while (1)
  51.     {
  52.         int c;
  53.         char ch;
  54.         if (kbhit())
  55.         {
  56.             c = xgetch();
  57.             if (c == 301)      // Alt-X to exit
  58.                 break;      // break out of while(1) loop.
  59.             char st[212];
  60.             switch(c)
  61.             {
  62.                 case 304:      // Alt-B to set baud rate
  63.                     printf("\nCurrent baud rate is %d\n",
  64.                         m.GetSpeed());
  65.                     printf("New baud rate (300-19200): ");
  66.                     if (scanf("%7s", st) == 1)
  67.                     {
  68.                         int s = atoi(st);
  69.                         if (s > 299 && s < 19201)
  70.                             m.SetSpeed(s);
  71.                     }
  72.                     break;
  73.                 case 287:      // Alt-S to shell
  74.                     printf("\nExternal DOS command: ");
  75.                     if (scanf("%211s", st) == 1)
  76.                         system(st);
  77.                     printf("\nExiting DOS shell . . . You may continue.\n");
  78.                     break;
  79.                 default:
  80.                     m.Send(char(c));  // avoid sending (int) c
  81.                     break;
  82.             }  // switch(c)
  83.         }  // if kbhit()
  84.         if ((m.Receive(ch)) != -1)
  85.             putchar(ch);
  86.     }  // while(1)
  87.  
  88.  
  89.     // Finished.  Clean up line before exiting to prevent lockups.
  90.     m.DropDTR();
  91.     m.Pause();
  92.     return 0;
  93. }
  94.  
  95.